$(function() {
    validateRule();
    $('.i-checks').iCheck({checkboxClass: 'icheckbox_square-green-login'});
});

$.validator.setDefaults({
    submitHandler: function() {
        login();
    }
});





function login() {
    var username = $("#username").val();
    var password = $("#password").val();

    // console.info(ctxPath);
    $.ajax({
        url: "ajaxLogin",
        type: "POST",
        dataType: "JSON",
        traditional: true,
        data: {
            username: username,
            password: password
        },
        success: function(r) {
            if (r.msg == "登录成功") {
                location.href = 'index';
            }else if (r.msg == "密码错误"){
                alert("用戶名密碼錯誤");
            }else if (r.msg == "登录失败，该用户已被冻结"){
                alert("用戶名密碼錯誤");
            }else if (r.msg == "该用户不存在"){
                alert("用戶名密碼錯誤");
            }
        }
    });
}

function validateRule() {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#signupForm").validate({
        rules: {
            username: {
                required: true
            },
            password: {
                required: true
            }
        },
        messages: {
            username: {
                required: icon + "请输入您的用户名",
            },
            password: {
                required: icon + "请输入您的密码",
            }
        }
    })
}